#ifndef VICL_H
#define VICL_H

#include <curses.h>
#include "vix.h"

#define SCR_WIDTH       80
#define SCR_HEIGHT      25-1

#define VICL_INFO_RESET() if(1){ info_screen_y = 2; info_screen_x = 2; wclear(info_screen); wrefresh(info_screen); }
#define VICL_INFO(...) if(1){ mvwprintw(info_screen, info_screen_y++, info_screen_x, __VA_ARGS__); wrefresh(info_screen); }

#define VICL_TITLE(...) if(1){ wclear(title_screen); wbkgd(screen, COLOR_PAIR(1)); \
                                 mvwprintw(title_screen, 0, 0, __VA_ARGS__); wrefresh(title_screen); }
                                 
#define VICL_STATUS(...) if(1){ wclear(status_screen); wbkgd(screen, COLOR_PAIR(1)); \
                                 mvwprintw(status_screen, 0, 0, __VA_ARGS__); wrefresh(status_screen); }

#define VICL_ERROR(...) if(1){ wclear(error_screen); wbkgd(error_screen, COLOR_PAIR(2)); \
                                mvwprintw(error_screen, 0, 0, __VA_ARGS__); wrefresh(error_screen); }
                                
#define VICL_QUIT(...) if(1){ wclear(error_screen); wbkgd(error_screen, COLOR_PAIR(2)); \
                               mvwprintw(error_screen, 0, 0, __VA_ARGS__); wrefresh(error_screen); \
                               fprintf(stderr, __VA_ARGS__); Vix_ReleaseHandle(jobHandle); VixHost_Disconnect(hostHandle); endwin(); }

WINDOW * mainwnd;
WINDOW * screen;

WINDOW * title_screen;
WINDOW * info_screen;
WINDOW * status_screen;
WINDOW * error_screen;

int info_screen_y, info_screen_x;

VixError err;
VixHandle jobHandle;
VixHandle hostHandle;

int keypress;

#define MAX_VMS 36
static char vmachine_ids[MAX_VMS] = 
{
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 
    'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};

struct vmachine_s
{
    bool usable;
    char* path;
    VixHandle handle;
} vmachine[MAX_VMS];
volatile int vmachine_idx;

// validate.c
int validate_ip_address(const char*, uint8_t*);
int validate_hostname(const char*);

// Core/connect.c
int setup_vmware_connection(const char*, const char*, const char*);

// Core/list_vm.c
int enumerate_virtual_machines(void);
int list_virtual_machines(void);

// Core/vm_open.c
int open_virtual_machine(int idx);

// Core/vm_power.c
int virtual_machine_power_options(int);
VixToolsState query_virtual_machine_power_state(int idx);
int list_power_options(int idx);

// Core/vm_info.c
VixPropertyID get_vm_vcpu_count(int idx);
VixPropertyID get_vm_memory_size(int idx);
char* read_vm_variable(int idx, const char* name);

// Core/ui_help.c
void vicl_info_help1(void);
void vicl_info_help2(void);

// Core/VMtools.c
int install_guest_vm_tools(int idx);

#endif
